/*
 * 数位拆分v2.0（4分）
 *
 * v1.0见02_week02/4_Numerical_Digit_Split_v1.c
 */

#include <stdio.h>

int main() {
	setbuf(stdout, NULL);

	int input, buffer[4], a = 0, b = 0;

	printf("Please input n:\n");
	scanf("%d", &input);

	// note: 将原来的n的每一位拆分出来
	for (int i = 3; i >= 0; --i) {
		buffer[i] = input % 10;
		input /= 10;
	}

	// note: 形成n的高两位和低两位，分别存在a和b
	a = 10 * buffer[0] + buffer[1];
	b = 10 * buffer[2] + buffer[3];

	// note: 输出a,b两个数
	printf("%d,%d\n", a, b);

	// note: 进行5种运算，并输出
	printf("sum=%d,sub=%d,multi=%d\n", a + b, a - b, a * b);
	// alert: 除法运算必须检验除数是否为0的情况
	if (b == 0) {
		printf("The second operator is zero!\n");

		return -2;
	} else {
		printf("dev=%.2f,mod=%d\n", (float) a / (float) b, a % b);
	}

	return 0;
}

// review: 此题由Online_Exercising - 02_week02 - 4引申
